package com.small.commom;

import java.util.LinkedList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

public class ActivityManager {
	private static LinkedList<Activity> acys;
	private static ActivityManager instance = null;
	
	private ActivityManager()
	{}
	
	public static ActivityManager getInstance()
	{
		if (instance == null)
		{
			instance = new ActivityManager();
			acys = new LinkedList<Activity>();
		}
		return instance;
	}
	
	public void Add(Activity acy)
	{
		acys.add(acy);
	}
	
	public void Remove(Activity acy)
	{
		acys.remove(acy);
	}
	
	public void Close()
	{
		Activity acy;
		while(acys.size() != 0)
		{
			acy = acys.poll();
			if (!acy.isFinishing())
			{
				acy.finish();
			}
		}
	}
	
	public void Start(Context context, Class<?> cls)
	{       
		Start(null, context, cls);
	}
	
	public void Start(Bundle bundle, Context context, Class<?> cls)
	{
	    Intent intent = new Intent();
	    if (bundle != null)
	    {
	        intent.putExtras(bundle);
	    }
	    intent.setClass(context, cls);
	    context.startActivity(intent);
	}
}

class MySecurityManager extends SecurityManager {   
    protected Class<?>[] getClassContext() {   
        return super.getClassContext();   
    }   
};  
